﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MapLibrary
{
    public class Page<T> : System.Collections.IEnumerable
    {
        private int mPageNumber;
        private int mNumPerPage;
        private List<T> mToTrack;

        public Page(List<T> toTrack, int pageNumber, int numPerPage)
        {
            mToTrack = toTrack;
            mPageNumber = pageNumber;
            mNumPerPage = numPerPage;
        }

        public System.Collections.IEnumerator GetEnumerator()
        {
            int start = (mPageNumber - 1) * mNumPerPage;
            int stop = Math.Min((mPageNumber) * mNumPerPage, mToTrack.Count);

            for (int i = start; i < stop; i++)
            {
                yield return mToTrack[i];
            }
        }

        public T this[int index]
        {
            get
            {
                return mToTrack[(mPageNumber - 1) * mNumPerPage + index];
            }
        }
    }
}
